package test.administrator.example.com.mvptest1.framework.support.viewstate.fragment;

import test.administrator.example.com.mvptest1.framework.support.base.MvpBasePresenter;
import test.administrator.example.com.mvptest1.framework.support.fragment.MvpFragment;
import test.administrator.example.com.mvptest1.framework.lce.MvpLceView;
import test.administrator.example.com.mvptest1.framework.support.fragment.FragmentMvpDelegate;
import test.administrator.example.com.mvptest1.framework.support.viewstate.MvpViewStateDelegateCallback;
import test.administrator.example.com.mvptest1.framework.support.viewstate.RestorableViewState;

/**
 * 第一重代理：生命周期->Fragment->代理对象
 * 第二重代理：目标对象
 * Created by thinkpad on 2018/8/9.
 */
public abstract class MvpViewStateFragment<V extends MvpLceView, P extends MvpBasePresenter<V>, VS extends RestorableViewState<V>> extends MvpFragment<V, P> implements MvpViewStateDelegateCallback<V, P, VS> {

	//特点：持有目标对象引用
	@Override
	protected FragmentMvpDelegate<V, P> getMvpDelegate() {
		if (mvpDelegate == null) {
			mvpDelegate = new FragmentMvpViewStateDelegateImpl<V, P, VS>(this, this, true, true);
		}
		return mvpDelegate;
	}

	protected VS viewState;
	//是否正在恢复
	private boolean restoringViewState = false;

	@Override
	public VS getViewState() {
		return viewState;
	}

	@Override
	public void setViewState(VS viewState) {
		this.viewState = viewState;
	}

	@Override
	public void setRestoringViewState(boolean restoringViewState) {
		this.restoringViewState = restoringViewState;
	}

	@Override
	public boolean isRestoringViewState() {
		return restoringViewState;
	}

}
